using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NET.Library.Web.Forms.DataControls.GridViews
{
    /// <summary>
    /// Reference Web Controls in a GridView Control.
    /// </summary>
    public static class GridViewControls
    {
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// HyperLink Control Reference
        /// </summary>
        /// <param name="controlName">ID of the Control</param>
        /// <param name="e"></param>
        /// <returns>HyperLink</returns>
        ///----------------------------------------------------------------------------------
        public static HyperLink HyperLinkControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as HyperLink;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static HyperLink HyperLinkControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as HyperLink;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static HyperLink HyperLinkFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as HyperLink;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Label Control Reference
        /// </summary>
        /// <param name="controlName">ID of the Control</param>
        /// <param name="e"></param>
        /// <returns>Label</returns>
        ///----------------------------------------------------------------------------------
        public static Label LabelControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as Label;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static Label LabelControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as Label;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static Label LabelFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as Label;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Literal Control Reference
        /// </summary>
        /// <param name="controlName">ID of the Control</param>
        /// <param name="e"></param>
        /// <returns>Literal</returns>
        ///----------------------------------------------------------------------------------
        public static Literal LiteralControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as Literal;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static Literal LiteralControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as Literal;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static Literal LiteralFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as Literal;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// TextBox Control Reference
        /// </summary>
        /// <param name="controlName">ID of the Control</param>
        /// <param name="e"></param>
        /// <returns>TextBox</returns>
        ///----------------------------------------------------------------------------------
        public static TextBox TextBoxControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as TextBox;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static TextBox TextBoxControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as TextBox;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static TextBox TextBoxFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as TextBox;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Image Control Reference
        /// </summary>
        /// <param name="controlName">ID of the Control</param>
        /// <param name="e"></param>
        /// <returns>TextBox</returns>
        ///----------------------------------------------------------------------------------
        public static Image ImageControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as Image;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static Image ImageControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as Image;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static Image ImageFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as Image;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// CheckBox Control Reference
        /// </summary>
        /// <param name="controlName">ID of the Control</param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static CheckBox CheckBoxControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as CheckBox;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static CheckBox CheckBoxControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as CheckBox;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static CheckBox CheckBoxFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as CheckBox;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// CheckBoxList Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static CheckBoxList CheckBoxListControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as CheckBoxList;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static CheckBoxList CheckBoxListControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as CheckBoxList;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static CheckBoxList CheckBoxListFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as CheckBoxList;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// RadioButton Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static RadioButton RadioButtonControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as RadioButton;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static RadioButton RadioButtonControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as RadioButton;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static RadioButton RadioButtonFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as RadioButton;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// RadioButtonList Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static RadioButtonList RadioButtonListControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as RadioButtonList;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static RadioButtonList RadioButtonListControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as RadioButtonList;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static RadioButtonList RadioButtonListFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as RadioButtonList;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Button Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static Button ButtonControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as Button;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static Button ButtonControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as Button;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static Button ButtonFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as Button;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Calendar Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static Calendar CalendarControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as Calendar;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static Calendar CalendarControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as Calendar;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static Calendar CalendarFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as Calendar;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// DropDownList Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static DropDownList DropDownListControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as DropDownList;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static DropDownList DropDownListControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as DropDownList;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static DropDownList DropDownListFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as DropDownList;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// FileUpload Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static FileUpload FileUploadControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as FileUpload;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static FileUpload FileUploadControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as FileUpload;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static FileUpload FileUploadFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as FileUpload;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// HiddenField Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static HiddenField HiddenFieldControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as HiddenField;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static HiddenField HiddenFieldControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as HiddenField;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static HiddenField HiddenFieldFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as HiddenField;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        /// ImageButton Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static ImageButton ImageButtonControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as ImageButton;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static ImageButton ImageButtonControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as ImageButton;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static ImageButton ImageButtonFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as ImageButton;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        ///  Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static LinkButton LinkButtonControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as LinkButton;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static LinkButton LinkButtonControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as LinkButton;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static LinkButton LinkButtonFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as LinkButton;
        }

        ///----------------------------------------------------------------------------------
        /// <summary>
        ///  Control Reference
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        ///----------------------------------------------------------------------------------
        public static ListBox ListBoxControl(string controlName, GridViewRowEventArgs e)
        {
            return Control(controlName, e) as ListBox;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        public static ListBox ListBoxControl(string controlName, GridViewRow row)
        {
            return Control(controlName, row) as ListBox;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlName"></param>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static ListBox ListBoxFooterControl(string controlName, GridView gridView)
        {
            return FooterControl(controlName, gridView) as ListBox;
        }

        #region Private Methods
        ///----------------------------------------------------------------------------------
        /// <summary>
        /// Generic Control Reference
        /// </summary>
        /// <remarks>Used internally for all Control types.</remarks>
        /// <param name="controlName">ID of the Control</param>
        /// <param name="e"></param>
        /// <returns>Control</returns>
        ///----------------------------------------------------------------------------------
        private static Control Control(string controlName, GridViewRowEventArgs e)
        {
            return e.Row.FindControl(controlName);
        }
        
        private static Control Control(string controlName, GridViewRow row)
        {
            return row.FindControl(controlName);
        }

        //private static Control Control(string controlName, GridViewRow row)
        //{
        //    return row.FindControl(controlName);
        //}

        private static Control FooterControl(string controlName, GridView gridView)
        {
            return gridView.FooterRow.FindControl(controlName);
        }
        #endregion
    }
}
